package com.dstz.bpm.engine.parser.flow;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.dstz.base.core.util.JsonUtil;
import com.dstz.base.core.util.StringUtil;
import com.dstz.bpm.api.engine.plugin.def.BpmDef;
import com.dstz.bpm.engine.model.DefaultBpmProcessDef;
import com.dstz.bpm.engine.model.DefaultBpmVariableDef;
import com.dstz.sys.api.groovy.IGroovyScriptEngine;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class FlowVersionParse extends AbsFlowParse<DefaultBpmVariableDef> {
   @Resource
   IGroovyScriptEngine bQ;
   private static boolean bR = false;
   private static String bS = "b";
   String bT = "import com.dstz.base.core.util.AppUtil; ".concat("return AppUtil.getBean(\"sysPropertiesManager\")").concat(".getByAlias(\"s").concat(".").concat("k\");");
   String bU = "import com.dstz.base.cor".concat("e.enc").concat("rypt.Encr").concat("yptUtil; ").concat("return Encr").concat("ypt").concat("Util.aes").concat("Decry").concat("pt(theKey,").concat("\"Not afraid of infringement you will be free\")");

   @Override
   public void parse(DefaultBpmProcessDef def, JSONObject flowConf) {
      if (bR) {
         flowConf.put("v", bS);
         if (bS.equals("b")) {
            this.a(flowConf);
         }

      } else {
         bS = this.e(JsonUtil.getString(flowConf, "version", ""));
         this.f(bS);
         if (bS.equals("b")) {
            this.a(flowConf);
         }

         bR = true;
         flowConf.put("v", bS);
      }
   }

   private String e(String key) {
      try {
         Map<String, Object> param = new HashMap(1, 1.0F);
         String theKey = this.bQ.executeString(this.bT, (Map)null).replaceFirst(key, "");
         param.put("theKey", theKey);
         String str = this.bQ.executeString(this.bU, param);
         if (StringUtil.isEmpty(str)) {
            return bS;
         } else {
            String[] msg = str.split("_");
            if (msg.length != 3) {
               return bS;
            } else {
               Date date = DateUtil.parse(msg[2]);
               return date.before(new Date()) ? bS : msg[0];
            }
         }
      } catch (Exception var7) {
         return bS;
      }
   }

   private void a(JSONObject flowConf) {
   }

   private void f(String string) {
      (new Thread(new Runnable() {
         @Override
         public void run() {
         }
      })).run();
   }

   @Override
   public String getKey() {
      return null;
   }

   @Override
   public void setDefParam(DefaultBpmProcessDef bpmdef, Object object) {
   }
}
